let http = require('http')
let url = require('url')
let util = require('util')
let fs = require('fs')

let server = http.createServer((req, res) => {
  var pathname = url.parse(req.url).pathname
  console.log("file:" + pathname.substring(1))
  //console.log("file:" + pathname.substring(1))
  fs.readFile(pathname.substring(1), function(err, data) {
    if (err) {
      res.writeHead(404, {
        'Content-Type': 'text/html'
      })
    } else {
      res.writeHead(200, {
        'Content-Type': 'text/html'
      })
      res.write(data.toString())
    }
    res.end();
  })

//res.end(util.inspect(url.parse("http://localhost:8808/index.html?name=sky-Blue")))
}).listen(8808, () => {
  console.log("服务器已经运行,请打开浏览器 Http://localhost:8808/")
})
